package logic

import (
	"context"
	"smart-health-platforms/config"
	"user_srv/internal/dao"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListSessionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSessionLogic {
	return &ListSessionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListSessionLogic) ListSession(in *user.ListSessionRequest) (*user.ListSessionResponse, error) {
	byUser, err := dao.NewChatSessionDao(config.DB).ListByUser(config.Ctx, in.UserId)
	if err != nil {
		return nil, err
	}
	resp := &user.ListSessionResponse{}
	for _, v := range byUser {
		resp.Sessions = append(resp.Sessions, &user.Session{
			Id:    uint64(v.Id),
			Title: v.Title,
		})
	}
	return resp, nil
}
